package cn.com.dhcc.app.pub.core.util.settlement.compute;

import cn.com.dhcc.app.pub.core.util.settlement.compute.filter.MD5Filter;
import cn.com.dhcc.app.pub.core.util.settlement.compute.store.DataGroupHandler;
import cn.com.dhcc.app.pub.core.util.settlement.compute.store.DataProcessHandler;
import cn.com.dhcc.app.pub.core.util.settlement.compute.store.DefaultDataGroupHandler;
import cn.com.dhcc.app.pub.core.util.settlement.compute.store.DefaultDataProcessHandler;
import cn.com.dhcc.app.pub.core.util.settlement.compute.task.DataComputeResultTask;
import cn.com.dhcc.app.pub.core.util.settlement.compute.task.DataStoreTask;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * taskId-----------task001 orderid-----------order001 order002 order003
 * 
 * 
 * 模拟临时落地 50条数据
 * 
 * 模拟合并50条数据
 * 
 * 模拟再临时落地40条数据
 * 
 * 模拟合并40条数据
 * 
 * @author Administrator
 * 
 */
public class ComputeTest {

	public static void main(String[] args) throws Exception {
		DataGroupHandler groupHandler = new DefaultDataGroupHandler();
		groupHandler.addFilter(new MD5Filter());
		DataProcessHandler processHandler = new DefaultDataProcessHandler();
		ExecutorService executor = Executors.newSingleThreadExecutor();

		List<String> list = read(ComputeTest.class
				.getResourceAsStream("./1.txt"));

		Map<String, List<String>> map = new HashMap<String, List<String>>();
		map.put("user", list);// user表

		
		executor.submit(new DataStoreTask("order004", map, groupHandler,processHandler)); 
//		executor.submit(new DataMergeTask("order004","task001", processHandler));
		 

		// executor.submit(new DataComputeTask("task001", map, groupHandler,
		// processHandler));

		executor.submit(new DataComputeResultTask("taskid", "user",new Date(), processHandler));
	}

	public static List<String> read(InputStream is) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(is));
		String line = null;
		List<String> list = new ArrayList<String>();
		while ((line = reader.readLine()) != null) {
			list.add(line);
		}
		is.close();
		return list;
	}

}
